package com.alongstudio.account.commons.utils;

import java.io.Serializable;
import java.util.Properties;

import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.id.Configurable;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.type.Type;
import org.springframework.stereotype.Service;

/**
 * id生成器
 * @author 
 *
 */
@Service
public class IdentityGenerator implements IdentifierGenerator, Configurable{

	@Override
	public Serializable generate(SessionImplementor session, Object obj) throws HibernateException {              
        return  UUIDUtil.getUniquePrimaryKey();
    }  
  
    @Override
	public void configure(Type type, Properties params, Dialect d) throws MappingException {  
          
    }  
    public static void main(String[] args) {  
    	IdentityGenerator pu = new IdentityGenerator();       
        System.out.println(pu.generate(null, null));          
        /*int random = 32; 
        System.out.println(RandomStringUtils.randomNumeric(random)); 
        System.out.println(RandomStringUtils.randomAscii(random)); 
        System.out.println(RandomStringUtils.randomAlphabetic(random)); 
        System.out.println(RandomStringUtils.randomAlphanumeric(random));*/  
          
    }  
}
